﻿using EnglishAuction.BUS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EnglishAuction
{
    public partial class DeleteProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = int.Parse(Request.QueryString["ID"]);
                if (id > 0)
                {
                    SanPham sanPham = SanPhamBUS.GetDetailById(id);
                    lbGiaSan.Text = String.Format("{0:###,###}", sanPham.GiaSan);
                    lbLoaiSanPham.Text = sanPham.LoaiSanPham.TenLoaiSanPham;
                    lbTenSanPham.Text = sanPham.TenSanPham;
                    HinhDaiDien.ImageUrl = "images/" + sanPham.HinhAnh;                    
                    lbThoiGianDauGia.Text = String.Format("{0:###,###}", sanPham.ThoiGianDauGia)+ "Ngày";
                }
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["ID"]);
            SanPham sanPham = SanPhamBUS.GetUserByID(id);          
            Utilities.SendMail(sanPham.NguoiDung.Email, txtLiDoXoa.Text);            
            File.Delete(Server.MapPath("~/images/"+sanPham.HinhAnh));
            if (SanPhamBUS.Delete(sanPham.Id))
            {                
                Response.Redirect("~/ManageProduct.aspx");
            }
            
        }
    }
}